home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / Editors / emacs / Emacs-1.14b1-sources / sources / utility-src / fileutils / lib / posixtm.tab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-17  |  18.6 KB  |  788 lines  |  [TEXT/KAHL]

  1.  
  2. /*  A Bison parser, made from posixtm.y  */
  3.  
  4. #define    DIGIT    258
  5.  
  6. #line 19 "posixtm.y"
  7.  
  8.  
  9. #ifdef HAVE_CONFIG_H
  10. #if defined (CONFIG_BROKETS)
  11. /* We use <config.h> instead of "config.h" so that a compilation
  12.    using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
  13.    (which it would do because it found this file in $srcdir).  */
  14. #include <config.h>
  15. #else
  16. #include "config.h"
  17. #endif
  18. #endif
  19.  
  20. /* The following block of alloca-related preprocessor directives is here
  21.    solely to allow compilation by non GNU-C compilers of the C parser
  22.    produced from this file by old versions of bison.  Newer versions of
  23.    bison include a block similar to this one in bison.simple.  */
  24.    
  25. #ifdef __GNUC__
  26. #define alloca __builtin_alloca
  27. #else
  28. #ifdef HAVE_ALLOCA_H
  29. #include <alloca.h>
  30. #else
  31. #ifdef _AIX
  32.  #pragma alloca
  33. #else
  34. void *alloca ();
  35. #endif
  36. #endif
  37. #endif
  38.  
  39. #include "stdio.h"
  40. #include "sys/types.h"
  41.  
  42. #ifdef TM_IN_SYS_TIME
  43. #include <sys/time.h>
  44. #else
  45. #include <time.h>
  46. #endif
  47.  
  48. /* Some old versions of bison generate parsers that use bcopy.
  49.    That loses on systems that don't provide the function, so we have
  50.    to redefine it here.  */
  51. #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
  52. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  53. #endif
  54.  
  55. //#define YYDEBUG 1
  56.  
  57. /* Lexical analyzer's current scan position in the input string. */
  58. static char *curpos;
  59.  
  60. /* The return value. */
  61. static struct tm t;
  62.  
  63. time_t mktime ();
  64.  
  65. #define zzparse posixtime_zzparse
  66. static int zzlex ();
  67. static int zzerror ();
  68.  
  69. #ifndef YYLTYPE
  70. typedef
  71.   struct zzltype
  72.     {
  73.       int timestamp;
  74.       int first_line;
  75.       int first_column;
  76.       int last_line;
  77.       int last_column;
  78.       char *text;
  79.    }
  80.   zzltype;
  81.  
  82. #define YYLTYPE zzltype
  83. #endif
  84.  
  85. #ifndef YYSTYPE
  86. #define YYSTYPE int
  87. #endif
  88. #include "stdio.h"
  89.  
  90. #ifndef __STDC__
  91. #define const
  92. #endif
  93.  
  94.  
  95.  
  96. #define    YYFINAL        15
  97. #define    YYFLAG        -32768
  98. #define    YYNTBASE    5
  99.  
  100. #define YYTRANSLATE(x) ((unsigned)(x) <= 258 ? zztranslate[x] : 9)
  101.  
  102. static const char zztranslate[] = {     0,
  103.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  104.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  105.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  106.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  107.      2,     2,     2,     2,     2,     4,     2,     2,     2,     2,
  108.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  109.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  110.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  111.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  112.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  113.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  114.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  115.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  116.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  117.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  118.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  119.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  120.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  121.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  122.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  123.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  124.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  125.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  126.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  127.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  128.      2,     2,     2,     2,     2,     1,     2,     3
  129. };
  130.  
  131. static const short zzrline[] = {     0,
  132.     85,   114,   121,   128,   139,   142,   151
  133. };
  134.  
  135. #if YYDEBUG != 0
  136. static const char * const zztname[] = {     0,
  137. "error","$illegal.","DIGIT","'.'","date"
  138. };
  139. #endif
  140.  
  141. static const short zzr1[] = {     0,
  142.      5,     6,     6,     6,     7,     7,     8
  143. };
  144.  
  145. static const short zzr2[] = {     0,
  146.      6,     1,     2,     0,     0,     2,     2
  147. };
  148.  
  149. static const short zzdefact[] = {     0,
  150.      0,     0,     7,     0,     0,     4,     5,     2,     0,     1,
  151.      3,     6,     0,     0,     0
  152. };
  153.  
  154. static const short zzdefgoto[] = {    13,
  155.      7,    10,     2
  156. };
  157.  
  158. static const short zzpact[] = {     2,
  159.      5,     2,-32768,     2,     2,     2,    -3,     2,     2,-32768,
  160. -32768,-32768,     9,    10,-32768
  161. };
  162.  
  163. static const short zzpgoto[] = {-32768,
  164. -32768,-32768,    -2
  165. };
  166.  
  167.  
  168. #define    YYLAST        10
  169.  
  170.  
  171. static const short zztable[] = {     4,
  172.      9,     5,     6,     8,     1,    11,    12,     3,    14,    15
  173. };
  174.  
  175. static const short zzcheck[] = {     2,
  176.      4,     4,     5,     6,     3,     8,     9,     3,     0,     0
  177. };
  178. #define YYPURE 1
  179.  
  180. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  181. #line 3 "bison.simple"
  182.  
  183. /* Skeleton output parser for bison,
  184.    Copyright (C) 1984 Bob Corbett and Richard Stallman
  185.  
  186.    This program is free software; you can redistribute it and/or modify
  187.    it under the terms of the GNU General Public License as published by
  188.    the Free Software Foundation; either version 1, or (at your option)
  189.    any later version.
  190.  
  191.    This program is distributed in the hope that it will be useful,
  192.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  193.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  194.    GNU General Public License for more details.
  195.  
  196.    You should have received a copy of the GNU General Public License
  197.    along with this program; if not, write to the Free Software
  198.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  199.  
  200.  
  201. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  202. #include <alloca.h>
  203. #endif
  204.  
  205. /* This is the parser code that is written into each bison parser
  206.   when the %semantic_parser declaration is not specified in the grammar.
  207.   It was written by Richard Stallman by simplifying the hairy parser
  208.   used when %semantic_parser is specified.  */
  209.  
  210. /* Note: there must be only one dollar sign in this file.
  211.    It is replaced by the list of actions, each action
  212.    as one case of the switch.  */
  213.  
  214. #define zzerrok        (zzerrstatus = 0)
  215. #define zzclearin    (zzchar = YYEMPTY)
  216. #define YYEMPTY        -2
  217. #define YYEOF        0
  218. #define YYFAIL        goto zzerrlab;
  219. #define YYACCEPT    return(0)
  220. #define YYABORT     return(1)
  221. #define YYERROR        goto zzerrlab
  222.  
  223. #define YYTERROR    1
  224. #define YYERRCODE    256
  225.  
  226. #ifndef YYIMPURE
  227. #define YYLEX        zzlex()
  228. #endif
  229.  
  230. #ifndef YYPURE
  231. #define YYLEX        zzlex(&zzlval, &zzlloc)
  232. #endif
  233.  
  234. /* If nonreentrant, generate the variables here */
  235.  
  236. #ifndef YYIMPURE
  237.  
  238. int    zzchar;            /*  the lookahead symbol        */
  239. YYSTYPE    zzlval;            /*  the semantic value of the        */
  240.                 /*  lookahead symbol            */
  241.  
  242. YYLTYPE zzlloc;            /*  location data for the lookahead    */
  243.                 /*  symbol                */
  244.  
  245. int zznerrs;            /*  number of parse errors so far       */
  246. #endif  /* YYIMPURE */
  247.  
  248. #if YYDEBUG != 0
  249. int zzdebug;            /*  nonzero means print parse trace    */
  250. /* Since this is uninitialized, it does not stop multiple parsers
  251.    from coexisting.  */
  252. #endif
  253.  
  254. /*  YYMAXDEPTH indicates the initial size of the parser's stacks    */
  255.  
  256. #ifndef    YYMAXDEPTH
  257. #define YYMAXDEPTH 200
  258. #endif
  259.  
  260. /*  YYMAXLIMIT is the maximum size the stacks can grow to
  261.     (effective only if the built-in stack extension method is used).  */
  262.  
  263. #ifndef YYMAXLIMIT
  264. #define YYMAXLIMIT 10000
  265. #endif
  266.  
  267.  
  268. #line 90 "bison.simple"
  269. int
  270. zzparse()
  271. {
  272.   register int zzstate;
  273.   register int zzn;
  274.   register short *zzssp;
  275.   register YYSTYPE *zzvsp;
  276.   YYLTYPE *zzlsp;
  277.   int zzerrstatus;    /*  number of tokens to shift before error messages enabled */
  278.   int zzchar1;        /*  lookahead token as an internal (translated) token number */
  279.  
  280.   short    zzssa[YYMAXDEPTH];    /*  the state stack            */
  281.   YYSTYPE zzvsa[YYMAXDEPTH];    /*  the semantic value stack        */
  282.   YYLTYPE zzlsa[YYMAXDEPTH];    /*  the location stack            */
  283.  
  284.   short *zzss = zzssa;        /*  refer to the stacks thru separate pointers */
  285.   YYSTYPE *zzvs = zzvsa;    /*  to allow zzoverflow to reallocate them elsewhere */
  286.   YYLTYPE *zzls = zzlsa;
  287.  
  288.   int zzmaxdepth = YYMAXDEPTH;
  289.  
  290. #ifndef YYPURE
  291.   int zzchar;
  292.   YYSTYPE zzlval;
  293.   YYLTYPE zzlloc;
  294.   int zznerrs;
  295. #endif
  296.  
  297.   YYSTYPE zzval;        /*  the variable used to return        */
  298.                 /*  semantic values from the action    */
  299.                 /*  routines                */
  300.  
  301.   int zzlen;
  302.  
  303. #if YYDEBUG != 0
  304.   if (zzdebug)
  305.     fprintf(stderr, "Starting parse\n");
  306. #endif
  307.  
  308.   zzstate = 0;
  309.   zzerrstatus = 0;
  310.   zznerrs = 0;
  311.   zzchar = YYEMPTY;        /* Cause a token to be read.  */
  312.  
  313.   /* Initialize stack pointers.
  314.      Waste one element of value and location stack
  315.      so that they stay on the same level as the state stack.  */
  316.  
  317.   zzssp = zzss - 1;
  318.   zzvsp = zzvs;
  319.   zzlsp = zzls;
  320.  
  321. /* Push a new state, which is found in  zzstate  .  */
  322. /* In all cases, when you get here, the value and location stacks
  323.    have just been pushed. so pushing a state here evens the stacks.  */
  324. zznewstate:
  325.  
  326.   *++zzssp = zzstate;
  327.  
  328.   if (zzssp >= zzss + zzmaxdepth - 1)
  329.     {
  330.       /* Give user a chance to reallocate the stack */
  331.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  332.       YYSTYPE *zzvs1 = zzvs;
  333.       YYLTYPE *zzls1 = zzls;
  334.       short *zzss1 = zzss;
  335.  
  336.       /* Get the current used size of the three stacks, in elements.  */
  337.       int size = zzssp - zzss + 1;
  338.  
  339. #ifdef zzoverflow
  340.       /* Each stack pointer address is followed by the size of
  341.      the data in use in that stack, in bytes.  */
  342.       zzoverflow("parser stack overflow",
  343.          &zzss1, size * sizeof (*zzssp),
  344.          &zzvs1, size * sizeof (*zzvsp),
  345.          &zzls1, size * sizeof (*zzlsp),
  346.          &zzmaxdepth);
  347.  
  348.       zzss = zzss1; zzvs = zzvs1; zzls = zzls1;
  349. #else /* no zzoverflow */
  350.       /* Extend the stack our own way.  */
  351.       if (zzmaxdepth >= YYMAXLIMIT)
  352.     zzerror("parser stack overflow");
  353.       zzmaxdepth *= 2;
  354.       if (zzmaxdepth > YYMAXLIMIT)
  355.     zzmaxdepth = YYMAXLIMIT;
  356.       zzss = (short *) alloca (zzmaxdepth * sizeof (*zzssp));
  357.       bcopy ((char *)zzss1, (char *)zzss, size * sizeof (*zzssp));
  358.       zzvs = (YYSTYPE *) alloca (zzmaxdepth * sizeof (*zzvsp));
  359.       bcopy ((char *)zzvs1, (char *)zzvs, size * sizeof (*zzvsp));
  360. #ifdef YYLSP_NEEDED
  361.       zzls = (YYLTYPE *) alloca (zzmaxdepth * sizeof (*zzlsp));
  362.       bcopy ((char *)zzls1, (char *)zzls, size * sizeof (*zzlsp));
  363. #endif
  364. #endif /* no zzoverflow */
  365.  
  366.       zzssp = zzss + size - 1;
  367.       zzvsp = zzvs + size - 1;
  368. #ifdef YYLSP_NEEDED
  369.       zzlsp = zzls + size - 1;
  370. #endif
  371.  
  372. #if YYDEBUG != 0
  373.       if (zzdebug)
  374.     fprintf(stderr, "Stack size increased to %d\n", zzmaxdepth);
  375. #endif
  376.  
  377.       if (zzssp >= zzss + zzmaxdepth - 1)
  378.     YYABORT;
  379.     }
  380.  
  381. #if YYDEBUG != 0
  382.   if (zzdebug)
  383.     fprintf(stderr, "Entering state %d\n", zzstate);
  384. #endif
  385.  
  386. /* Do appropriate processing given the current state.  */
  387. /* Read a lookahead token if we need one and don't already have one.  */
  388. zzresume:
  389.  
  390.   /* First try to decide what to do without reference to lookahead token.  */
  391.  
  392.   zzn = zzpact[zzstate];
  393.   if (zzn == YYFLAG)
  394.     goto zzdefault;
  395.  
  396.   /* Not known => get a lookahead token if don't already have one.  */
  397.  
  398.   /* zzchar is either YYEMPTY or YYEOF
  399.      or a valid token in external form.  */
  400.  
  401.   if (zzchar == YYEMPTY)
  402.     {
  403. #if YYDEBUG != 0
  404.       if (zzdebug)
  405.     fprintf(stderr, "Reading a token: ");
  406. #endif
  407.       zzchar = YYLEX;
  408.     }
  409.  
  410.   /* Convert token to internal form (in zzchar1) for indexing tables with */
  411.  
  412.   if (zzchar <= 0)        /* This means end of input. */
  413.     {
  414.       zzchar1 = 0;
  415.       zzchar = YYEOF;        /* Don't call YYLEX any more */
  416.  
  417. #if YYDEBUG != 0
  418.       if (zzdebug)
  419.     fprintf(stderr, "Now at end of input.\n");
  420. #endif
  421.     }
  422.   else
  423.     {
  424.       zzchar1 = YYTRANSLATE(zzchar);
  425.  
  426. #if YYDEBUG != 0
  427.       if (zzdebug)
  428.     fprintf(stderr, "Next token is %d (%s)\n", zzchar, zztname[zzchar1]);
  429. #endif
  430.     }
  431.  
  432.   zzn += zzchar1;
  433.   if (zzn < 0 || zzn > YYLAST || zzcheck[zzn] != zzchar1)
  434.     goto zzdefault;
  435.  
  436.   zzn = zztable[zzn];
  437.  
  438.   /* zzn is what to do for this token type in this state.
  439.      Negative => reduce, -zzn is rule number.
  440.      Positive => shift, zzn is new state.
  441.        New state is final state => don't bother to shift,
  442.        just return success.
  443.      0, or most negative number => error.  */
  444.  
  445.   if (zzn < 0)
  446.     {
  447.       if (zzn == YYFLAG)
  448.     goto zzerrlab;
  449.       zzn = -zzn;
  450.       goto zzreduce;
  451.     }
  452.   else if (zzn == 0)
  453.     goto zzerrlab;
  454.  
  455.   if (zzn == YYFINAL)
  456.     YYACCEPT;
  457.  
  458.   /* Shift the lookahead token.  */
  459.  
  460. #if YYDEBUG != 0
  461.   if (zzdebug)
  462.     fprintf(stderr, "Shifting token %d (%s), ", zzchar, zztname[zzchar1]);
  463. #endif
  464.  
  465.   /* Discard the token being shifted unless it is eof.  */
  466.   if (zzchar != YYEOF)
  467.     zzchar = YYEMPTY;
  468.  
  469.   *++zzvsp = zzlval;
  470. #ifdef YYLSP_NEEDED
  471.   *++zzlsp = zzlloc;
  472. #endif
  473.  
  474.   /* count tokens shifted since error; after three, turn off error status.  */
  475.   if (zzerrstatus) zzerrstatus--;
  476.  
  477.   zzstate = zzn;
  478.   goto zznewstate;
  479.  
  480. /* Do the default action for the current state.  */
  481. zzdefault:
  482.  
  483.   zzn = zzdefact[zzstate];
  484.   if (zzn == 0)
  485.     goto zzerrlab;
  486.  
  487. /* Do a reduction.  zzn is the number of a rule to reduce with.  */
  488. zzreduce:
  489.   zzlen = zzr2[zzn];
  490.   zzval = zzvsp[1-zzlen]; /* implement default value of the action */
  491.  
  492. #if YYDEBUG != 0
  493.   if (zzdebug)
  494.     {
  495.       if (zzlen == 1)
  496.     fprintf (stderr, "Reducing 1 value via line %d, ",
  497.          zzrline[zzn]);
  498.       else
  499.     fprintf (stderr, "Reducing %d values via line %d, ",
  500.          zzlen, zzrline[zzn]);
  501.     }
  502. #endif
  503.  
  504.  
  505.   switch (zzn) {
  506.  
  507. case 1:
  508. #line 91 "posixtm.y"
  509. {
  510.              if (zzvsp[-5] >= 1 && zzvsp[-5] <= 12)
  511.            t.tm_mon = zzvsp[-5] - 1;
  512.          else {
  513.            YYABORT;
  514.          }
  515.          if (zzvsp[-4] >= 1 && zzvsp[-4] <= 31)
  516.            t.tm_mday = zzvsp[-4];
  517.          else {
  518.            YYABORT;
  519.          }
  520.          if (zzvsp[-3] >= 0 && zzvsp[-3] <= 23)
  521.            t.tm_hour = zzvsp[-3];
  522.          else {
  523.            YYABORT;
  524.          }
  525.          if (zzvsp[-2] >= 0 && zzvsp[-2] <= 59)
  526.            t.tm_min = zzvsp[-2];
  527.          else {
  528.            YYABORT;
  529.          }
  530.            ;
  531.     break;}
  532. case 2:
  533. #line 114 "posixtm.y"
  534. {
  535.                    t.tm_year = zzvsp[0];
  536.            /* Deduce the century based on the year.
  537.               See POSIX.2 section 4.63.3.  */
  538.            if (zzvsp[0] <= 68)
  539.              t.tm_year += 100;
  540.          ;
  541.     break;}
  542. case 3:
  543. #line 121 "posixtm.y"
  544. {
  545.                             t.tm_year = zzvsp[-1] * 100 + zzvsp[0];
  546.                 if (t.tm_year < 1900) {
  547.                   YYABORT;
  548.                 } else
  549.                   t.tm_year -= 1900;
  550.               ;
  551.     break;}
  552. case 4:
  553. #line 128 "posixtm.y"
  554. {
  555.                     time_t now;
  556.             struct tm *tmp;
  557.  
  558.                     /* Use current year.  */
  559.                     time (&now);
  560.             tmp = localtime (&now);
  561.             t.tm_year = tmp->tm_year;
  562.           ;
  563.     break;}
  564. case 5:
  565. #line 139 "posixtm.y"
  566. {
  567.                         t.tm_sec = 0;
  568.               ;
  569.     break;}
  570. case 6:
  571. #line 142 "posixtm.y"
  572. {
  573.                       if (zzvsp[0] >= 0 && zzvsp[0] <= 61)
  574.                 t.tm_sec = zzvsp[0];
  575.               else {
  576.                 YYABORT;
  577.               }
  578.             ;
  579.     break;}
  580. case 7:
  581. #line 151 "posixtm.y"
  582. {
  583.                           zzval = zzvsp[-1] * 10 + zzvsp[0];
  584.             ;
  585.     break;}
  586. }
  587.    /* the action file gets copied in in place of this dollarsign */
  588. #line 327 "bison.simple"
  589.  
  590.   zzvsp -= zzlen;
  591.   zzssp -= zzlen;
  592. #ifdef YYLSP_NEEDED
  593.   zzlsp -= zzlen;
  594. #endif
  595.  
  596. #if YYDEBUG != 0
  597.   if (zzdebug)
  598.     {
  599.       short *ssp1 = zzss - 1;
  600.       fprintf (stderr, "state stack now");
  601.       while (ssp1 != zzssp)
  602.     fprintf (stderr, " %d", *++ssp1);
  603.       fprintf (stderr, "\n");
  604.     }
  605. #endif
  606.  
  607.   *++zzvsp = zzval;
  608.  
  609. #ifdef YYLSP_NEEDED
  610.   zzlsp++;
  611.   if (zzlen == 0)
  612.     {
  613.       zzlsp->first_line = zzlloc.first_line;
  614.       zzlsp->first_column = zzlloc.first_column;
  615.       zzlsp->last_line = (zzlsp-1)->last_line;
  616.       zzlsp->last_column = (zzlsp-1)->last_column;
  617.       zzlsp->text = 0;
  618.     }
  619.   else
  620.     {
  621.       zzlsp->last_line = (zzlsp+zzlen-1)->last_line;
  622.       zzlsp->last_column = (zzlsp+zzlen-1)->last_column;
  623.     }
  624. #endif
  625.  
  626.   /* Now "shift" the result of the reduction.
  627.      Determine what state that goes to,
  628.      based on the state we popped back to
  629.      and the rule number reduced by.  */
  630.  
  631.   zzn = zzr1[zzn];
  632.  
  633.   zzstate = zzpgoto[zzn - YYNTBASE] + *zzssp;
  634.   if (zzstate >= 0 && zzstate <= YYLAST && zzcheck[zzstate] == *zzssp)
  635.     zzstate = zztable[zzstate];
  636.   else
  637.     zzstate = zzdefgoto[zzn - YYNTBASE];
  638.  
  639.   goto zznewstate;
  640.  
  641. zzerrlab:   /* here on detecting error */
  642.  
  643.   if (! zzerrstatus)
  644.     /* If not already recovering from an error, report this error.  */
  645.     {
  646.       ++zznerrs;
  647.       zzerror("parse error");
  648.     }
  649.  
  650.   if (zzerrstatus == 3)
  651.     {
  652.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  653.  
  654.       /* return failure if at end of input */
  655.       if (zzchar == YYEOF)
  656.     YYABORT;
  657.  
  658. #if YYDEBUG != 0
  659.       if (zzdebug)
  660.     fprintf(stderr, "Discarding token %d (%s).\n", zzchar, zztname[zzchar1]);
  661. #endif
  662.  
  663.       zzchar = YYEMPTY;
  664.     }
  665.  
  666.   /* Else will try to reuse lookahead token
  667.      after shifting the error token.  */
  668.  
  669.   zzerrstatus = 3;        /* Each real token shifted decrements this */
  670.  
  671.   goto zzerrhandle;
  672.  
  673. zzerrdefault:  /* current state does not do anything special for the error token. */
  674.  
  675. #if 0
  676.   /* This is wrong; only states that explicitly want error tokens
  677.      should shift them.  */
  678.   zzn = zzdefact[zzstate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  679.   if (zzn) goto zzdefault;
  680. #endif
  681.  
  682. zzerrpop:   /* pop the current state because it cannot handle the error token */
  683.  
  684.   if (zzssp == zzss) YYABORT;
  685.   zzvsp--;
  686.   zzstate = *--zzssp;
  687. #ifdef YYLSP_NEEDED
  688.   zzlsp--;
  689. #endif
  690.  
  691. #if YYDEBUG != 0
  692.   if (zzdebug)
  693.     {
  694.       short *ssp1 = zzss - 1;
  695.       fprintf (stderr, "Error: state stack now");
  696.       while (ssp1 != zzssp)
  697.     fprintf (stderr, " %d", *++ssp1);
  698.       fprintf (stderr, "\n");
  699.     }
  700. #endif
  701.  
  702. zzerrhandle:
  703.  
  704.   zzn = zzpact[zzstate];
  705.   if (zzn == YYFLAG)
  706.     goto zzerrdefault;
  707.  
  708.   zzn += YYTERROR;
  709.   if (zzn < 0 || zzn > YYLAST || zzcheck[zzn] != YYTERROR)
  710.     goto zzerrdefault;
  711.  
  712.   zzn = zztable[zzn];
  713.   if (zzn < 0)
  714.     {
  715.       if (zzn == YYFLAG)
  716.     goto zzerrpop;
  717.       zzn = -zzn;
  718.       goto zzreduce;
  719.     }
  720.   else if (zzn == 0)
  721.     goto zzerrpop;
  722.  
  723.   if (zzn == YYFINAL)
  724.     YYACCEPT;
  725.  
  726. #if YYDEBUG != 0
  727.   if (zzdebug)
  728.     fprintf(stderr, "Shifting error token, ");
  729. #endif
  730.  
  731.   *++zzvsp = zzlval;
  732. #ifdef YYLSP_NEEDED
  733.   *++zzlsp = zzlloc;
  734. #endif
  735.  
  736.   zzstate = zzn;
  737.   goto zznewstate;
  738. }
  739. #line 155 "posixtm.y"
  740.  
  741. static int
  742. zzlex ()
  743. {
  744.   char ch = *curpos++;
  745.  
  746.   if (ch >= '0' && ch <= '9')
  747.     {
  748.       zzlval = ch - '0';
  749.       return DIGIT;
  750.     }
  751.   else if (ch == '.' || ch == 0)
  752.     return ch;
  753.   else
  754.     return '?';            /* Cause an error.  */
  755. }
  756.  
  757. static int
  758. zzerror ()
  759. {
  760.   return 0;
  761. }
  762.  
  763. /* Parse a POSIX-style date and return it, or (time_t)-1 for an error.  */
  764.  
  765. time_t
  766. posixtime (s)
  767.      char *s;
  768. {
  769.   curpos = s;
  770.   /* Let mktime decide whether it is daylight savings time.  */
  771.   t.tm_isdst = -1;
  772.   if (zzparse ())
  773.     return (time_t)-1;
  774.   else
  775.     return mktime (&t);
  776. }
  777.  
  778. /* Parse a POSIX-style date and return it, or NULL for an error.  */
  779.  
  780. struct tm *
  781. posixtm (s)
  782.      char *s;
  783. {
  784.   if (posixtime (s) == -1)
  785.     return NULL;
  786.   return &t;
  787. }
  788.